(define (cube x) (* x x x))

(define (inc x) (+ x 1))

(define (simpson f a b n)
  (define (sum term a next b)
    (if (> a b)
      0
      (+ (term a) (sum term (next a) next b))))
  (define h (/ (- b a) n))
  (define (y_k k) (f (+ a (* h k))))
  (define (simpson-iter k)
    (* (cond ( (or (= k 0) (= k n)) 1)
             ((odd? k) 4)
             (else 2))
       (y_k k)))
  (* (/ h 3) (sum simpson-iter 0 inc n)))
